package controller;

import entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import service.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class TableController {

    @Autowired
    private SelectAllPurchaseService selectAllPurchaseService;

    @Autowired
    private SelectAllUserService selectAllUserService;

    @Autowired
    private SelectAllGoodsService selectAllGoodsService;

    @Autowired
    private SelectSupplierByIdService selectSupplierByIdService;

    @Autowired
    private SelectUserByRoleService selectUserByRoleService;
    @Autowired
    private SelectAllSaleService selectAllSaleService;

    @RequestMapping("/purchaseTable")
    public String selectAllPurchase(Model model){
        List<goods2> goods = selectAllGoodsService.findAllGoods();
        List<purchase2> purchase2s = selectAllPurchaseService.selectAllPurchase();
        model.addAttribute("purchase2s",purchase2s);
        //采购员
        int role = 1;
        List<user> purchase = selectUserByRoleService.selectUserByRole(role);
        model.addAttribute("goods",goods);
        model.addAttribute("purchase",purchase);
        return "Table/Purchase";
    }

    @RequestMapping("/saleTable")
    public String selectAllSale(Model model){
        List<goods2> goods = selectAllGoodsService.findAllGoods();
        List<sale2> sale_list = selectAllSaleService.SelectAllSale();
        model.addAttribute("sale_list",sale_list);
        //销售员
        int role = 2;
        List<user> sale = selectUserByRoleService.selectUserByRole(role);
        model.addAttribute("goods",goods);
        model.addAttribute("sale",sale);
        return "Table/Sale";
    }

    @RequestMapping("/goodsTable")
    public String selectAllGoods(Model model){
        List<goods2> goods = selectAllGoodsService.findAllGoods();
        //供应商
        int role = 3;
        List<user> suppliers = selectUserByRoleService.selectUserByRole(role);
        model.addAttribute("goods",goods);
        model.addAttribute("suppliers",suppliers);
        return "Table/GoodsTable";
    }

    @RequestMapping("/stockTable")
    public String selectAllGoods2(Model model){
        List<goods2> goods = selectAllGoodsService.findAllGoods();
        //供应商
        int role = 3;
        List<user> suppliers = selectUserByRoleService.selectUserByRole(role);
        model.addAttribute("goods",goods);
        model.addAttribute("suppliers",suppliers);
        return "Table/StockTable";
    }

    @RequestMapping("/userTable")
    public String UserTable(Model model){
        List<user> users = selectAllUserService.selectAllUser();
        model.addAttribute("users",users);
        return "Table/UserTable";
    }

    @RequestMapping("/eployeeTable")
    public String EployeeTable(Model model){
        List<user> users = selectAllUserService.selectAllUser();
        model.addAttribute("users",users);
        return "Table/EployeeTable";
    }


}
